'******************************************************************************************************** 'Sample code for Wanderbug feelers, PICAXE 14M2, preloaded * '******************************************************************************************************** let dirsb = %00111111 'configure Port B pins as outputs (see P15 of manual 2) let dirsc = %00000010 'configure Port C pins as inputs except C.1(see P15 of manual 2) main: 'main loop starts here for normal forward running low c.1 'buzzer off low b.0:low b.1 'both LEDs off high b.2:low b.3 'right wheel forward high b.4:low b.5 'left wheel forward if pinc.3 = 0 then left 'left bumper has hit an object if pinc.4 = 0 then right 'right bumper has hit an object goto main 'no objects, carry on forward left: 'left bumper object routine low b.2:high b.3 'reverse right wheel low b.4:low b.5 'stop left wheel, high b.1 'left LED on high c.1 'sound the buzzer pause 500 'pause for 500 milliseconds while wanderbug reverses away goto main 'go forward again in a new direction right: 'right bumper object routine low b.2:low b.3 'stop right wheel low b.4:high b.5 'reverse left wheel high b.0 'right LED on high c.1 'sound the buzzer pause 500 'pause for 500 milliseconds while wanderbug reverses away goto main 'go forward again in a new direction '******************************************************************************************************** 'Sample code for Wanderbug ultrasonic rangefinder, PICAXE 14M2 * '******************************************************************************************************** 'input pin c.0 = echo 'output pin c.2 = trig let dirsb = %00111111 'configure Port B pins as outputs (see P15 of manual 2) let dirsc = %00000110 'configure Port C pins (see P15 of manual 2) symbol range = w0 'range symbol speed = w1 'speed start: 'forward low c.1:low b.0:low b.1 'buzzer off, LEDs off gosub rangechk 'check range if range < 10 then 'less than 10 cm, then gosub back 'reverse away endif speed = 10 * range min 160 max 400 'slower as we get closer pwmout b.2, 100, speed:low b.3 'right wheel forward pwmout b.4, 100, speed:low b.5 'left wheel forward if pinc.3 = 0 then gosub rgt 'left bumper has hit an object if pinc.4 = 0 then gosub lft 'right bumper has hit an object goto start 'check range again back: 'backup and reverse turn right pwmout b.4, off 'pwm off on pwmout b.2, off 'both wheels high b.0: high b.1 'boths LEDs on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 500 'reverse for 500 milliseconds low b.5 'stop left wheel high c.1 'sound the buzzer pause 500 'turn for 500 milliseconds return 'continue lft: 'reverse turn left high b.1 'left LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 300 'reverse for 300 milliseconds low b.3 'stop right wheel, high c.1 'sound the buzzer pause 200 'turn for 200 milliseconds return 'continue rgt: 'reverse turn right high b.0 'right LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 300 'reverse for 300 milliseconds low b.5 'stop left wheel high c.1 'sound the buzzer pause 200 'turn for 200 milliseconds return 'continue rangechk: 'get range to obstruction setfreq m8 'set frequency to 8 MHz pulsout c.2,3 'send trigger pulsin c.0,1,range 'get range in 10uS steps range = range * 5 / 58 'convert to cm pause 50 'pause 25 ms setfreq m4 'set frequency to 4 MHz return 'continue '******************************************************************************************************** 'Sample code for Wanderbug line follower, PICAXE 14M2 * '******************************************************************************************************** 'input pin c.0 = shade 'automatically calibrates for light level let dirsb = %00111111 'configure Port B pins as outputs (see P15 of manual 2) let dirsc = %00000110 'configure Port C pins as inputs except C.1(see P15 of manual 2) symbol speed = 160 'set speed between 160 and 250 depending on width of line symbol shade = w0 'shade value symbol minsh = w1 symbol maxsh = w2 minsh = 512 'start between 0 and 1024 maxsh = 512 'start between 0 and 1024 start: 'forward low c.1:low b.0:low b.1 'buzzer off, LEDs off readadc10 c.0, shade 'read shade into w0 if shade <= minsh then 'calibrate minimum minsh = shade + 8 endif if shade >= maxsh then 'calibrate maximum maxsh = shade - 8 endif if shade >= minsh and shade <= maxsh then pwmout b.2, 100, speed:low b.3 'right wheel forward pwmout b.4, 100, speed:low b.5 'left wheel forward endif if shade < minsh then 'right PQ on black line pwmout b.4, 100, speed 'left wheel forward pwmout b.2,0,0 'right wheel stopped endif 'turn right back on line if shade > maxsh then 'left PQ on black line pwmout b.2, 100, speed 'right wheel forward pwmout b.4,0,0 'left wheel stopped endif 'turn left back on line if pinc.3 = 0 then right 'left bumper has hit an object if pinc.4 = 0 then left 'right bumper has hit an object if pinc.3 = 0 and pinc.4 = 0 then back 'both bumpers have hit an object goto start 'no object detected, continue forward back: 'backup and reverse turn right high b.0:high b.1 'both LEDs on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 500 'reverse for 500 milliseconds low b.5 'stop left wheel high c.1 'sound the buzzer pause 500 'turn for 500 milliseconds goto start 'continue forward left: 'reverse turn left high b.0 'right LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 300 'reverse for 300 milliseconds low b.3 'stop right wheel, high c.1 'sound the buzzer pause 200 'turn for 200 milliseconds goto start 'continue forward right: 'reverse turn right high b.1 'left LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 300 'reverse for 300 milliseconds low b.5 'stop left wheel high c.1 'sound the buzzer pause 200 'turn for 200 milliseconds goto start 'continue forward '******************************************************************************************************** 'Sample code for Wanderbug infrared obstacle avoider, PICAXE 14M2 * '******************************************************************************************************** 'input pin 0 = sense 'output pin 0 = look right, right LED 'output pin 1 = look left, left LED let dirsb = %00111111 'configure Port B pins as outputs (see P15 of manual 2) let dirsc = %00000010 'configure Port C pins as inputs except C.1(see P15 of manual 2) setfreq m8 'faster pulses to match IR detector, pause is 500us start: 'forward low c.1:low b.0:low b.1 'buzzer off, LEDs off high b.2:low b.3 'right wheel forward high b.4:low b.5 'left wheel forward pulsout b.0,1 'send a pulse from the right if pinc.0 = 0 then gosub lft 'return pulse detected, go left endif pulsout b.1,1 'send a pulse from the left if pinc.0 = 0 then gosub rgt 'return pulse detected, go right endif if pinc.3 = 0 then gosub rgt 'left bumper has hit an object endif if pinc.4 = 0 then gosub lft 'right bumper has hit an object endif goto start 'no object detected, continue forward lft: 'reverse turn left high b.0 'right LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 600 'reverse for 300 milliseconds low b.3 'stop right wheel, high c.1 'sound the buzzer pause 400 'turn for 200 milliseconds return 'continue forward rgt: 'reverse turn right high b.1 'left LED on low b.2:high b.3 'right wheel backward low b.4:high b.5 'left wheel backward pause 600 'reverse for 300 milliseconds low b.5 'stop left wheel high c.1 'sound the buzzer pause 400 'turn for 200 milliseconds return 'continue forward '******************************************************************************************************** 'Sample code for Wanderbug RC Transmitter, PICAXE 08M2 * '******************************************************************************************************** #picaxe 08M2 dirs = %00000001 'configure 08M2 symbol code = $00 '$00 to $f0, 16 unit codes symbol buts = b0 'button code symbol oldbuts = b1 'last button code main: 'main loop buts = pins 'read the buttons command pause 20 'slow the loop if buts = oldbuts then main 'no change, read buttons again oldbuts = buts 'store the new command buts = buts/2 'shift right one bit buts = buts & $0f 'clear the top nibble buts = buts + code 'add the unit code serout 0,n1200_4,(85,85,85,85,127,buts) 'new command, send it goto main 'check for another command '******************************************************************************************************** 'Sample code for Wanderbug RC Receiver, PICAXE 14M2 * '******************************************************************************************************** #picaxe 14M2 let dirsb = %00111111 'configure Port B pins as outputs (see P15 of manual 2) let dirsc = %00000010 'configure Port C pins as inputs except C.1(see P15 of manual 2) symbol code = $00 '$00 to $f0, 16 unit codes symbol incode = b0 'incoming code from transmitter symbol name = b1 'incoming ID code main: 'main loop starts here if pinc.3 = 0 then left 'left bumper has hit an object if pinc.4 = 0 then right 'right bumper has hit an object serin [100,main],c.0,n1200_4,(127),incode 'wait for correct signal from transmitter name = incode & $f0 'check if it's my code if name = code then 'yes it is, set the outputs pinb.2 = bit0 'to suit the commands received pinb.3 = bit1 pinb.4 = bit3 pinb.5 = bit2 endif goto main 'carry on forward left: 'left bumper object routine low b.2:high b.3 'reverse right wheel low b.4:low b.5 'stop left wheel, high b.1 'left LED on high c.1 'sound the buzzer pause 500 'pause for 500 milliseconds while wanderbug reverses away low c.1: low b.1 'buzzer off, left LED off low b.3 'stop right wheel goto main 'look for new signal right: 'right bumper object routine low b.2:low b.3 'stop right wheel low b.4:high b.5 'reverse left wheel high b.0 'right LED on high c.1 'sound the buzzer pause 500 'pause for 500 milliseconds while wanderbug reverses away low c.1: low b.0 'buzzer off, right LED off low b.5 'stop left wheel goto main 'look for new signal